package com.example.commentserver.controller;

import com.example.commentserver.params.CommentParams;
import com.example.commentserver.params.PageCommentParams;
import com.example.commentserver.service.CommentService;
import com.example.commentserver.vo.CommentVO;
import com.example.userserver.enums.ReturnEnum;
import com.example.userserver.vo.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/comment-server")
@Api(tags = "评论接口")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @ApiOperation(value = "获取评论")
    @PostMapping(value = "/page")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<PageInfo<CommentVO>> pageComment(@RequestBody PageCommentParams pageCommentParams) {
        return new Result(commentService.pageComment(pageCommentParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "删除评论")
    @PostMapping(value = "/delete")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result deleteComment(@RequestParam String id) {
        commentService.deleteComment(id);
        return new Result(null, ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "修改评论")
    @PostMapping(value = "/update")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result updateComment(@RequestBody CommentParams commentParams) {
        return new Result(commentService.updateComment(commentParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "新增评论")
    @PostMapping(value = "/insert")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result insertComment(@RequestBody CommentParams commentParams) {
        return commentService.insertComment(commentParams);
    }
}
